package com.hang.controller;

import com.hang.common.Result;
import com.hang.model.Clazz;
import com.hang.service.*;
import com.hang.vo.FeedBackVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("statistic")
@Api(tags = "统计控制器")
@RequiredArgsConstructor
public class StatisticsController {
    private final LeaveService leaveService;

    private final StudentService studentService;

    private final TeacherService teacherService;

    private final ClazzService clazzService;

    private final TaskService taskService;

    private final AdminService adminService;

    @GetMapping("studentLeavesCount/{studentId}")
    @ApiOperation(value = "获取学生请假条数")
    public Result getStudentLeavesCount(
            @PathVariable("studentId") String studentId
    ){
        Integer count = leaveService.getStudentCounts(studentId);
        return Result.ok(count);
    }

    @GetMapping("studentClazzCount/{studentId}")
    @ApiOperation(value = "获取学生课程数目")
    public Result getClazzCount(
            @PathVariable("studentId") String studentId
    ){
        Integer count = clazzService.getClazzCount(studentId);
        return Result.ok(count);
    }

    @GetMapping("studentTaskCount/{studentId}")
    @ApiOperation(value = "获取学生考勤数目")
    public Result getTaskCount(
            @PathVariable("studentId") String studentId
    ){
        Integer count = taskService.getTaskCount(studentId);
        return Result.ok(count);
    }

    @GetMapping("teacherLeavesCount/{teacherId}")
    @ApiOperation(value = "获取老师管理的请假条数")
    public Result getTeacherLeavesCount(
            @PathVariable("teacherId") String teacherId
    ){
        Integer count = leaveService.getTeacherCounts(teacherId);
        return Result.ok(count);
    }

    @GetMapping("teacherClazzCount/{teacherId}")
    @ApiOperation(value = "获取老师课程数目")
    public Result getTeacherClazzCount(
            @PathVariable("teacherId") String teacherId
    ){
        Integer count = clazzService.getTeacherClazzCounts(teacherId);
        return Result.ok(count);
    }

    @GetMapping("teacherTaskCount/{teacherId}")
    @ApiOperation(value = "获取老师考勤数目")
    public Result getTeacherTaskCount(
            @PathVariable("teacherId") String teacherId
    ){
        Integer count = taskService.getTeacherTaskCounts(teacherId);
        return Result.ok(count);
    }

    /***
     * 教师端总体统计内容：
     *      老师最近一周的所有课程的考勤打卡情况
     *       数据返回：
     *          List:
     *          > 1.班级名称
     *          > 2.班级上课时间
     *          > 3.{该周内班级的所有任务考勤情况}
     * @param teacherId
     * @return
     */
    @GetMapping("teacherStatistics/{teacherId}/{page}/{size}")
    @ApiOperation(value = "分页获取最近一周老师的所有班级考勤情况")
    public Result getTeacherStatistics(
        @PathVariable("teacherId") String teacherId,
        @PathVariable("page") Integer page,
        @PathVariable("size") Integer size
    ){
        //获取老师的班级列表
        List<Clazz> clazzList = teacherService.getHisList(teacherId,page,size);

        //查看该班级这一周的任务
        Map<String,Object> map = taskService.statisticsWeek(clazzList);

        //判断是否还有数据
        if(Boolean.TRUE.equals(teacherService.hasMoreData(teacherId,page,size))){
            return Result.ok(map,Boolean.TRUE);
        }
        return Result.ok(map,Boolean.FALSE);
    }

    @GetMapping("studentStatistics/{studentId}")
    @ApiOperation(value = "获取最近一周学生的打卡考勤情况")
    public Result getStudentStatistics(
        @PathVariable("studentId") String studentId
    ){
        //获取学生的考勤列表
        List<Clazz> clazzList = studentService.getHisList(studentId, 1, Integer.MAX_VALUE);

        //根据学生班级获取最近一周的考勤任务的打卡情况
        Map<String,Object> map = taskService.getTaskResult(clazzList,studentId);

        return Result.ok(map);
    }
}